/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.youan.log.modules.audit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youan.log.modules.audit.entity.SdCityDbAttackedAnalysis;
import com.youan.log.modules.audit.excelexportentity.AttackSdDbCountryExcel;
import com.youan.log.modules.audit.mapper.SdCityDbAttackedAnalysisMapper;
import com.youan.log.modules.audit.service.ISdCityDbAttackedAnalysisService;
import com.youan.log.modules.audit.vo.SdCityDbAttackedAnalysisVO;
import com.youan.log.util.ExcelUtils;
import org.springblade.core.tool.utils.BeanUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *  服务实现类
 *
 * @author BladeX
 * @since 2021-03-31
 */
@Service
public class SdCityDbAttackedAnalysisServiceImpl extends ServiceImpl<SdCityDbAttackedAnalysisMapper, SdCityDbAttackedAnalysis> implements ISdCityDbAttackedAnalysisService {

	@Override
	public IPage<SdCityDbAttackedAnalysisVO> selectSdCityDbAttackedAnalysisPage(IPage<SdCityDbAttackedAnalysisVO> page, SdCityDbAttackedAnalysisVO sdCityDbAttackedAnalysis) {
		return page.setRecords(baseMapper.selectSdCityDbAttackedAnalysisPage(page, sdCityDbAttackedAnalysis));
	}

	@Override
	public List<SdCityDbAttackedAnalysis> detail(String attackedCity) {
		LambdaQueryWrapper<SdCityDbAttackedAnalysis> sdCityDbAttackedAnalysisLqw = new LambdaQueryWrapper<SdCityDbAttackedAnalysis>()
				.eq(SdCityDbAttackedAnalysis::getAttackedCity, attackedCity);
		List<SdCityDbAttackedAnalysis> result = list(sdCityDbAttackedAnalysisLqw);
		return result;
	}

	@Override
	public IPage<SdCityDbAttackedAnalysisVO> selectAttackSdDbCountry(IPage<SdCityDbAttackedAnalysisVO> page, SdCityDbAttackedAnalysisVO sdCityDbAttackedAnalysis) {
		return page.setRecords(baseMapper.selectAttackSdDbCountryPage(page, sdCityDbAttackedAnalysis));
	}

	@Override
	public void exportExcel(SdCityDbAttackedAnalysisVO sdCityDbAttackedAnalysis, HttpServletResponse response) {
		List<SdCityDbAttackedAnalysis> result = baseMapper.selectSdCityDbAttackedAnalysis(sdCityDbAttackedAnalysis);
		String filePath = ExcelUtils.wirte2Excel(SdCityDbAttackedAnalysis.class, result);
		ExcelUtils.exportExcel(filePath, response,true);
	}

	@Override
	public void exportAttackSdDbCountryExcel(SdCityDbAttackedAnalysisVO sdCityDbAttackedAnalysis, HttpServletResponse response) {
		List<SdCityDbAttackedAnalysis> result = baseMapper.selectAttackSdDbCountry(sdCityDbAttackedAnalysis);
		List<AttackSdDbCountryExcel> attackSdDbCountryExcelList = BeanUtil.copy(result, AttackSdDbCountryExcel.class);
		String filePath = ExcelUtils.wirte2Excel(AttackSdDbCountryExcel.class, attackSdDbCountryExcelList);
		ExcelUtils.exportExcel(filePath, response,true);
	}

}
